﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace Common
{
    [Serializable]
    public class EshubaMenu : EshubaLink, INotifyPropertyChanged
    {
        public EshubaMenu() { }

        private EshubaMenu(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.ToolTip = info.TryGetValue<string>("ToolTip");
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("ToolTip", ToolTip);
        }

        public override string GetRelativePath()
        {
            EshubaMenu parentMenu = EshubaCache.Instance.MenuCache.TryGetValue(this.ParentGuid);
            return GetParentRelativePath(parentMenu) + "\\" + this.Text;
        }

        public string ToolTip { get; set; }

        private ObservableCollection<EshubaMenu> _children = new ObservableCollection<EshubaMenu>();
        public ObservableCollection<EshubaMenu> Children
        {
            get
            {
                if (_children == null) _children = new ObservableCollection<EshubaMenu>();
                return _children;
            }
            set { _children = value; }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string value)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(value));
            }
        }
    }
}
